package cn.itcast.web.controller;

import cn.itcast.domain.system.User;
import com.sun.org.apache.bcel.internal.generic.RETURN;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class BaseController {

    @Autowired
    protected HttpServletRequest request;

    @Autowired
    protected HttpServletResponse response;

    @Autowired
    protected HttpSession session;


    /**
     * 获取当前登录用户的企业id
     *   1、获取当前登录的用户
     *   2、获取用户的企业id
     */
    public String getLoginCompanyId() {
        Object obj = session.getAttribute("loginUser");
        if(obj != null) {
            User user = (User) obj;
            return user.getCompanyId();
        }
        return "";//模拟企业id
    }


    //获取当前登录用户的企业名称
    public String getLoginCompanyName() {
        Object obj = session.getAttribute("loginUser");
        if(obj != null) {
            User user = (User) obj;
            return user.getCompanyName();
        }
        return "";
    }

    //获取当前登录的用户对象
    public User getLoginUser() {
        Object obj = session.getAttribute("loginUser");
        if(obj != null) {
            User user = (User) obj;
            return user;
        }
        return null;
    }
}
